home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / bccapp.zip / PULLDOWN.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  4KB  |  217 lines

  1. /*
  2.  *
  3.  * Class Implementation for Pulldown menu system
  4.  *
  5.  * (C) 1990 Vision Software
  6.  *
  7.  * $Id: pulldown.c 1.2001 91/04/25 15:07:58 pcalvin release $
  8.  *
  9.  * Comments:
  10.  *
  11.  * This class provides the traditional view of Pulldown menus.  Implementation
  12.  * is simplified because POPUP provides most of the lower level routines
  13.  *
  14.  * Bugs:
  15.  *
  16.  *    None documented
  17.  *
  18.  */
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <conio.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24.  
  25. #include <stdhdr.h>
  26. #include <adl.h>
  27. #include <menu.h>
  28.  
  29. #include "lowlevel.h"
  30.  
  31. /*
  32.  * Pulldown system is based upon the popup menu.
  33.  */
  34. PULLDOWN::PULLDOWN(ROW row,CBAR cbarTotal,PBAR pbarMenu) : POPUP(szNil)
  35.     {
  36.     Assert(pbarMenu != pbarNil);
  37.  
  38.     rowDisplay = row;
  39.     cbarMax = cbarTotal;
  40.     pbar = pbarMenu;
  41.     pcolTabs = 0;
  42.     szHotKeys = 0;
  43.     }
  44.  
  45. /*
  46.  * Show the menu bar..
  47.  */
  48. VOID PULLDOWN::ShowBar(VOID)
  49.     {
  50.     CURSOR crs(fFalse);
  51.     CHAR cch;
  52.     COL col;
  53.     CBAR cbar;
  54.  
  55.     if (pcolTabs != 0)
  56.         delete pcolTabs;
  57.  
  58.     pcolTabs = new COL[cbarMax];
  59.     if (szHotKeys != 0)
  60.         delete szHotKeys;
  61.  
  62.     szHotKeys = new char[cbarMax+1];
  63.  
  64.     ClearRow(rowDisplay,1,colGlobalWindowRight,coRed,coCyan);
  65.  
  66.     col = 3;
  67.     for (cbar=0;cbar<cbarMax;cbar++)
  68.         {
  69.         pcolTabs[cbar] = col;
  70.         szHotKeys[cbar] = toupper(pbar[cbar].sz[pbar[cbar].cchHotKey]);
  71.         HotString(rowDisplay,col,pbar[cbar].cchHotKey,pbar[cbar].sz,coRed,coCyan);
  72.         col += strlen(pbar[cbar].sz) + 2;
  73.         }
  74.  
  75.     szHotKeys[cbarMax] = '\0';
  76.     }
  77.  
  78. /*
  79.  * Answers with an ASCII code for the character that was entered
  80.  * Answers cdNil if that character is used..
  81.  */
  82. CD PULLDOWN::CdGet(VOID)
  83.     {
  84.     BOOL fContinue,fSelected;
  85.     CD cd;
  86.     SZ sz;
  87.     ROW rowOriginal,crow;
  88.     COL colOriginal,colLeft,colRight;
  89.     PENT pentBase;
  90.     CENT cent;
  91.     CBAR cbar;
  92.  
  93.     Assert(pcolTabs != 0);
  94.     Assert(szHotKeys != szNil);
  95.  
  96.     /*
  97.      * Make POPUP::Help point to this level
  98.      */
  99.     help.Replace("Press the Alt-Key combination for the desired menu");
  100.  
  101.     /*
  102.      * Normalized input..
  103.      */
  104.     cd = CdInput();
  105.  
  106.     if (cd < 0xff)
  107.         return (cd);
  108.     else
  109.         cd = CdFromAltCd(cd);
  110.  
  111.     if (cd == cdNil || (!(sz = strchr(szHotKeys,cd))))
  112.         return (cd);
  113.     else
  114.         cbar = sz - szHotKeys;
  115.  
  116.     fSelected = fFalse;
  117.     while (!fSelected)
  118.         {
  119.         fLeftExit = (cbar > 0) ? fTrue : fFalse;
  120.         fRightExit = (cbar + 1 < cbarMax) ? fTrue :fFalse;
  121.  
  122.         colLeft = pcolTabs[cbar];
  123.         HotString(rowDisplay,colLeft,pbar[cbar].cchHotKey,pbar[cbar].sz,coBlack,coGreen);
  124.         cent = CentGet(rowDisplay,colLeft,pbar[cbar].cent,pbar[cbar].pent);
  125.         HotString(rowDisplay,colLeft,pbar[cbar].cchHotKey,pbar[cbar].sz,coRed,coCyan);
  126.         /*
  127.          * If centains some legal value, exit, otherwise, find
  128.          * out which key exited.
  129.          */
  130.         if (cent == centError)
  131.             {
  132.             switch (CdExitKey())
  133.                 {
  134.             case cdEscape:
  135.                 return (cdNil);
  136.             case cdCursorLeft:
  137.                 cbar -= 1;
  138.                 break;
  139.             case cdCursorRight:
  140.                 cbar += 1;
  141.                 break;
  142.                 }
  143.             }
  144.         else
  145.             {
  146.             fSelected = fTrue;
  147.             }
  148.         }
  149.  
  150.     return (cdNil);
  151.     }
  152.  
  153.  
  154. /*
  155.  * This family of methods answers CENT nil if the key should escape
  156.  * the popup, Otherwise it returns the new CD value
  157.  */
  158. BOOL PULLDOWN::FHandleCd(CENT &rcent,CD cd,PENT pent,WINDOW &rwnd)
  159.     {
  160.     BOOL fContinue = fTrue;
  161.  
  162.     switch (cd)
  163.         {
  164.     case cdCursorRight:
  165.         if (fRightExit)
  166.             {
  167.             fContinue = fFalse;
  168.             rcent = centError;
  169.             }
  170.         break;
  171.     case cdCursorLeft:
  172.         if (fLeftExit)
  173.             {
  174.             fContinue = fFalse;
  175.             rcent = centError;
  176.             }
  177.         break;
  178.     default:
  179.         fContinue = POPUP::FHandleCd(rcent,cd,pent,rwnd);
  180.         break;
  181.         }
  182.  
  183.     return (fContinue);
  184.     }
  185.  
  186. /*
  187.  *    Translates the input character from Alt-Alpha, into
  188.  *    uppercase alpha.
  189.  *    Character translation table is derived from Layout
  190.  *    of MS-DOS keyboard.  This is obviously not-portable,
  191.  *    similar hacking will be required for UN*X etc.
  192.  */
  193. CD PULLDOWN::CdFromAltCd(CD cd)
  194.     {
  195.     STATIC CONST CD rgcdAltTranslate[] = 
  196.         {
  197.         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  198.         'Q','W','E','R','T','Y','U','I','O','P',0,0,0,0,
  199.          'A','S','D','F','G','H','J','K','L',0,0,0,0,0,
  200.           'Z','X','C','V','B','N','M',0
  201.         };
  202.  
  203.     STATIC CONST CD cdKeyMax = sizeof(rgcdAltTranslate) / sizeof(rgcdAltTranslate[0]); 
  204.     /*
  205.      *    If character was Alt-Combination, translate back, otherwise
  206.      *    it is now Nil
  207.      */
  208.     cd >>= 8;
  209.  
  210.     if (cd < cdKeyMax)
  211.         cd = rgcdAltTranslate[cd];
  212.     else    
  213.         cd = cdNil;
  214.  
  215.     return (cd);
  216.     }
  217.